﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using System.IO;
using System.Web.Script.Serialization;
using System.Data;

namespace website.Equipment
{
    /// <summary>
    /// EquInfo 的摘要说明
    /// </summary>
    public class EquInfo : IHttpHandler
    {
        string Action = "";
        public void ProcessRequest(HttpContext context)
        {
            Action = RequstString("Action");
            context.Response.ContentType = "text/plain";
            if (Action == "addEquTypeInfo")
            {
                string EquTypeName = RequstString("EquTypeName");
                string EquTypeRemark = RequstString("EquTypeRemark");
                string EquIndex = RequstString("EquIndex");
                context.Response.Write(addEquTypeInfo(EquTypeName,EquTypeRemark,EquIndex));
            }
            else if (Action == "GetEquTypeInfo")
            {
                string sidx = RequstString("sidx");
                string sord = RequstString("sord");
                string keyvalue = RequstString("keyword");
                string EquIndex = RequstString("EquIndex");

                context.Response.Write(GetEquTypeInfo(sidx, sord, keyvalue, EquIndex));
            }

            else if (Action == "initEquTypeList")
            {
                context.Response.Write(initEquTypeList());
            }
            else if (Action == "addEquKaoHao")
            {
                string EquNo = RequstString("EquNo");
                string EquType = RequstString("EquType");
                string Remark = RequstString("Remark");
                context.Response.Write(addEquKaoHao(EquNo, EquType, Remark));
            }

            //当是  宏大用户登录  获取设备列表信息
            else if (Action == "initEquListByHongda")
            {
                string sidx = RequstString("sidx");
                string sord = RequstString("sord");
                string keyvalue = RequstString("keyword");
                string CustomerName = RequstString("CustomerName");
                context.Response.Write(initEquListByHongda(sidx, sord, keyvalue, CustomerName));
            }

            //当是 客户登录 获取所购设备列表
            else if (Action == "initEquListByCustomerID")
            {
                string sidx = RequstString("sidx");
                string sord = RequstString("sord");
                string keyvalue = RequstString("keyword");
                string CustomerName = RequstString("CustomerName");
                context.Response.Write(initEquListByCustomerID(sidx, sord, keyvalue, CustomerName));
            }
            //设置纺纱品种
            else if (Action == "savefangshakind")
            {
                string TaiHao = RequstString("TaiHao");
                string FangShaKind = RequstString("FangShaKind");
                string CustomerID = RequstString("CustomerID");
                string EquNo = RequstString("EquNo");
                string FangShaDate = RequstString("FangShaDate");
                context.Response.Write(savefangshakind(TaiHao,EquNo, FangShaKind, FangShaDate, CustomerID));
            }

            else if (Action == "initfangshabyid")
            {
                string FangshaID = RequstString("FangshaID");
                context.Response.Write(initfangshabyid(FangshaID));
            }

            else if (Action == "saveShengChanfangshakind")
            {
                string FangShaKind = RequstString("FangShaKind");
                string CustomerID = RequstString("CustomerID");
                string OutPutTarget = RequstString("OutPutTarget");
                string FangShaDate = RequstString("FangShaDate");
                context.Response.Write(saveShengChanfangshakind(FangShaKind, CustomerID, OutPutTarget, FangShaDate));
            }

            else if (Action == "editShengChanfangshakind")
            {
                string FangShaKind = RequstString("FangShaKind");
                string ID = RequstString("ID");
                string OutPutTarget = RequstString("OutPutTarget");
                string FangShaDate = RequstString("FangShaDate");
                context.Response.Write(editShengChanfangshakind(FangShaKind, OutPutTarget, FangShaDate,ID));
            }

            else if (Action == "initShengChanSetInfo")
            {
                string CustomerID = RequstString("CustomerID");
                context.Response.Write(initShengChanSetInfo(CustomerID));
            }


            // 设置维护周期
            else if (Action == "saveMaintenanceCycle")
            {
                string TaiHao = RequstString("TaiHao");
                string MaintenanceCycle = RequstString("MaintenanceCycle");
                string CustomerID = RequstString("CustomerID");
                string EquNo = RequstString("EquNo");
                context.Response.Write(saveMaintenanceCycle(TaiHao,EquNo, MaintenanceCycle, CustomerID));
            }

            //设备维护操作
            else if (Action == "maintenanceEquInfo")
            {
                string TaiHao = RequstString("TaiHao");
                string EquNo = RequstString("EquNo");
                string CustomerID = RequstString("CustomerID");
                context.Response.Write(maintenanceEquInfo(TaiHao,EquNo, CustomerID));
            }
            else if (Action == "GetEquAlarmInfo")
            {
                string sidx = RequstString("sidx");
                string sord = RequstString("sord");
                string keyvalue = RequstString("keyword");

                context.Response.Write(GetEquAlarmInfo(sidx, sord, keyvalue));
            }
            else if (Action == "deleteEquTypeInfo")
            {
                context.Response.Write(deleteEquTypeInfo());

            }
            else if (Action == "deleteEquInfo")
            {
                context.Response.Write(deleteEquInfo());
            }
            else if (Action == "deleteEquTypeInfoguidao")
            {
                context.Response.Write(deleteEquTypeInfoguidao());
            }
            ///编辑设备类型初始化界面
            else if (Action == "initeditequtype")
            {
                context.Response.Write(initeditequtype());
            }

            // 保存编辑  设备类型
            else if (Action == "editequtype")
            {
                string TypeID = RequstString("TypeID");
                string FeatureID = RequstString("FeatureID");
                string EquTypeName = RequstString("EquTypeName");
                string EquTypeRemark = RequstString("EquTypeRemark");
                string EquIndex = RequstString("EquIndex");
                string EquTypeFeatures = RequstString("EquTypeFeatures");
                string FeaturesContent = RequstString("FeaturesContent");
                string MaintenanceCycle = RequstString("MaintenanceCycle");
                string ChangeEquNo = RequstString("ChangeEquNo");
                context.Response.Write(editequtype(TypeID,FeatureID, EquTypeName, EquTypeRemark, EquIndex, EquTypeFeatures, FeaturesContent, MaintenanceCycle, ChangeEquNo));
            }

           // 保存编辑  设备类型
            else if (Action == "editequtypeguidao")
            {
                string TypeID = RequstString("TypeID");
                string EquTypeName = RequstString("EquTypeName");
                string EquTypeRemark = RequstString("EquTypeRemark");
                string EquIndex = RequstString("EquIndex");

                context.Response.Write(editequtypeguidao(TypeID, EquTypeName, EquTypeRemark, EquIndex));
            }

            //保存设备类型特性
            else if (Action == "saveEquTypeFeature")
            {
                string EquTypeFeatures = RequstString("EquTypeFeatures");
                string FeaturesContent = RequstString("FeaturesContent");
                string MaintenanceCycle = RequstString("MaintenanceCycle");

                context.Response.Write(saveEquTypeFeature(EquTypeFeatures, FeaturesContent, MaintenanceCycle));
            }

            //得到设备类型特性列表
            else if (Action == "getEquTypeFeatureList")
            {
                string sidx = RequstString("sidx");
                string sord = RequstString("sord");
                string EquTypeName = RequstString("EquTypeName");

                context.Response.Write(getEquTypeFeatureList(sidx, sord, EquTypeName));
            }

            ///编辑设备类型特性初始化界面
            else if (Action == "initEquTypeFeaterEditForm")
            {
                context.Response.Write(initEquTypeFeaterEditForm());
            }

            // 保存编辑 设备类型特性
            else if (Action == "editEquTypeFeature")
            {
                string FeatureID = RequstString("FeatureID");
                string EquTypeFeatures = RequstString("EquTypeFeatures");
                string FeaturesContent = RequstString("FeaturesContent");
                string MaintenanceCycle = RequstString("MaintenanceCycle");
                context.Response.Write(editEquTypeFeature(FeatureID, EquTypeFeatures, FeaturesContent, MaintenanceCycle));
            }

            // 新增设备类型界面  如果点击关闭按钮  就删除未分配到设备类型的特性
            else if (Action == "deleteuntypefeature")
            {
                context.Response.Write(deleteuntypefeature());

            }

            //保存新增设备类型   带有设备类型特性
            else if (Action == "saveEquTypeWithTexing")
            {
                string EquTypeName = RequstString("EquTypeName");
                string EquTypeRemark = RequstString("EquTypeRemark");
                string EquIndex = RequstString("EquIndex");
                context.Response.Write(addEquTypeInfo(EquTypeName, EquTypeRemark, EquIndex));
            }

            //保存  编辑设备信息
            else if (Action == "saveeditequ")
            {
                string EquNo = RequstString("EquNo");
                string EquNewNo = RequstString("EquNewNo");  
                string Remark = RequstString("Remark");
                context.Response.Write(saveeditequ(EquNo,EquNewNo, Remark));
            }

            ///初始化设备报警编辑界面
            else if (Action == "initeditequalarm")
            {
                context.Response.Write(initeditequalarm());
            }

            //保存  编辑设备故障信息
            else if (Action == "saveeditequalarm")
            {
                string AlarmID = RequstString("AlarmID");
                string AlarmName = RequstString("AlarmName");
                string AlarmHandle = RequstString("AlarmHandle");
                string note = RequstString("note");
                context.Response.Write(saveeditequalarm(AlarmID, AlarmName, AlarmHandle, note));
            }

            else
            {
                var stream = new StreamReader(context.Request.InputStream).ReadToEnd();
                var msgdata = new JavaScriptSerializer().Deserialize<MSG>(stream);

                if (msgdata.Action == "saveEquTypeWithTexing")
                {
                    context.Response.Write(saveEquTypeWithTexing(msgdata.EquTypeName, msgdata.EquTypeRemark, msgdata.EquIndex, msgdata.EquTypeTexingID));
                }
            }
        }


        public string initEquTypeList()
        {
            string json = EquInfoBLL.initEquTypeList();
            return json;
        }

        /// <summary>
        /// 初始化设备类型列表
        /// </summary>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="keyvalue"></param>
        /// <param name="EquIndex"></param>
        /// <returns></returns>
        public string GetEquTypeInfo(string sidx, string sord, string keyvalue, string EquIndex)
        {
            string strJson = "";
            DataTable dt = EquInfoBLL.GetEquTypeInfo(sidx,sord,keyvalue,EquIndex); 

            if (dt != null)
            {
                string page = RequstString("page");
                //String page =Re .getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数 
                string rows = RequstString("rows");  // 取得每页显示行数，,注意这是jqgrid自身的参数 
                int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得，在此只是模拟) 
                int totalPage = totalRecord % Convert.ToInt16(rows) == 0 ? totalRecord
                / Convert.ToInt16(rows) : totalRecord / Convert.ToInt16(rows)
                + 1; // 计算总页数 
                int index = (Convert.ToInt16(page) - 1) * Convert.ToInt16(rows); // 开始记录数 
                int pageSize = Convert.ToInt16(rows);
                strJson = "{\"page\":" + page + ",\"total\": " + totalPage + "  ,\"records\":" + dt.Rows.Count.ToString() + ",\"rows\":[";
                for (int j = index; j < pageSize + index && j < totalRecord; j++)
                {
                    strJson += "{";
                    strJson += "\"id\":\"" + (j + 1).ToString() + "\",";
                    strJson += "\"cell\":";

                    strJson += "[";
                    strJson += "\"" + dt.Rows[j]["ID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["FeatureID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquTypeName"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquTypeRemark"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquTypeFeatures"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["FeaturesContent"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["MaintenanceCycle"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["ChangeEquNo"].ToString() + "\"";
                    strJson += "]";
                    strJson += "}";
                    if (j != pageSize + index - 1 && j != totalRecord - 1)
                    {
                        strJson += ",";
                    }
                }
            }
            else
            {
                strJson = "{\"page\":1,\"total\":0,\"records\":0,\"rows\":[";

            }
            strJson = strJson.Trim().TrimEnd(new char[] { ',' });
            strJson += "]}";
            return strJson;
        }

        /// <summary>
        /// 初始化 设备报警设置信息
        /// </summary>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="keyvalue"></param>
        /// <returns></returns>
        public string GetEquAlarmInfo(string sidx, string sord, string keyvalue)
        {
            string strJson = "";
            DataTable dt = EquInfoBLL.GetEquAlarmInfo(sidx, sord, keyvalue);

            if (dt != null)
            {
                string page = RequstString("page");
                //String page =Re .getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数 
                string rows = RequstString("rows");  // 取得每页显示行数，,注意这是jqgrid自身的参数 
                int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得，在此只是模拟) 
                int totalPage = totalRecord % Convert.ToInt16(rows) == 0 ? totalRecord
                / Convert.ToInt16(rows) : totalRecord / Convert.ToInt16(rows)
                + 1; // 计算总页数 
                int index = (Convert.ToInt16(page) - 1) * Convert.ToInt16(rows); // 开始记录数 
                int pageSize = Convert.ToInt16(rows);
                strJson = "{\"page\":" + page + ",\"total\": " + totalPage + "  ,\"records\":" + dt.Rows.Count.ToString() + ",\"rows\":[";
                for (int j = index; j < pageSize + index && j < totalRecord; j++)
                {
                    strJson += "{";
                    strJson += "\"id\":\"" + (j + 1).ToString() + "\",";
                    strJson += "\"cell\":";
                    strJson += "[";
                    strJson += "\"" + dt.Rows[j]["id"].ToString() + "\",";
                    strJson += "\"" + DBUlitity.JSONTools.EncodeTextareaChar(dt.Rows[j]["AlarmName"].ToString()) + "\",";
                    strJson += "\"" + DBUlitity.JSONTools.EncodeTextareaChar(dt.Rows[j]["AlarmHandle"].ToString()) + "\",";
                    strJson += "\"" + DBUlitity.JSONTools.EncodeTextareaChar(dt.Rows[j]["note"].ToString()) + "\"";

                    strJson += "]";
                    strJson += "}";
                    if (j != pageSize + index - 1 && j != totalRecord - 1)
                    {
                        strJson += ",";
                    }
                }
            }
            else
            {
                strJson = "{\"page\":1,\"total\":0,\"records\":0,\"rows\":[";

            }
            strJson = strJson.Trim().TrimEnd(new char[] { ',' });
            strJson += "]}";
            //strJson = DBUlitity.JSONTools.EncodeTextareaChar(strJson);
            return strJson;
        }

        /// <summary>
        /// 当是  宏大用户登录  获取设备列表信息
        /// </summary>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="keyvalue"></param>
        /// <param name="EquIndex"></param>
        /// <returns></returns>
        public string initEquListByHongda(string sidx, string sord, string keyvalue, string CustomerName)
        {
            string strJson = "";


            DataTable dt = EquInfoBLL.initEquListByHongda(sidx, sord, keyvalue, CustomerName);

            if (dt != null)
            {
                string page = RequstString("page");
                //String page =Re .getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数 
                string rows = RequstString("rows");  // 取得每页显示行数，,注意这是jqgrid自身的参数 
                int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得，在此只是模拟) 
                int totalPage = totalRecord % Convert.ToInt16(rows) == 0 ? totalRecord
                / Convert.ToInt16(rows) : totalRecord / Convert.ToInt16(rows)
                + 1; // 计算总页数 
                int index = (Convert.ToInt16(page) - 1) * Convert.ToInt16(rows); // 开始记录数 
                int pageSize = Convert.ToInt16(rows);
                strJson = "{\"page\":" + page + ",\"total\": " + totalPage + "  ,\"records\":" + dt.Rows.Count.ToString() + ",\"rows\":[";
                for (int j = index; j < pageSize + index && j < totalRecord; j++)
                {
                    strJson += "{";
                    strJson += "\"id\":\"" + (j + 1).ToString() + "\",";
                    strJson += "\"cell\":";

                    strJson += "[";
                    strJson += "\"" + dt.Rows[j]["ID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquNo"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquType"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["CreateTime"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["CustomName"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["TaiHao"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["UseDate"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["Remark"].ToString() + "\"";
                    strJson += "]";
                    strJson += "}";
                    if (j != pageSize + index - 1 && j != totalRecord - 1)
                    {
                        strJson += ",";
                    }
                }
            }
            else
            {
                strJson = "{\"page\":1,\"total\":0,\"records\":0,\"rows\":[";

            }
            strJson = strJson.Trim().TrimEnd(new char[] { ',' });
            strJson += "]}";
            return strJson;
        }


        /// <summary>
        /// 当是 客户登录 获取所购设备列表
        /// </summary>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="keyvalue"></param>
        /// <param name="CustomerName"></param>
        /// <returns></returns>
        public string initEquListByCustomerID(string sidx, string sord, string keyvalue, string CustomerName)
        {
            string strJson = "";


            DataTable dt = EquInfoBLL.initEquListByCustomerID(sidx, sord, keyvalue, CustomerName);

            if (dt != null)
            {
                string page = RequstString("page");
                //String page =Re .getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数 
                string rows = RequstString("rows");  // 取得每页显示行数，,注意这是jqgrid自身的参数 
                int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得，在此只是模拟) 
                int totalPage = totalRecord % Convert.ToInt16(rows) == 0 ? totalRecord
                / Convert.ToInt16(rows) : totalRecord / Convert.ToInt16(rows)
                + 1; // 计算总页数 
                int index = (Convert.ToInt16(page) - 1) * Convert.ToInt16(rows); // 开始记录数 
                int pageSize = Convert.ToInt16(rows);
                strJson = "{\"page\":" + page + ",\"total\": " + totalPage + "  ,\"records\":" + dt.Rows.Count.ToString() + ",\"rows\":[";
                for (int j = index; j < pageSize + index && j < totalRecord; j++)
                {
                    strJson += "{";
                    strJson += "\"id\":\"" + (j + 1).ToString() + "\",";
                    strJson += "\"cell\":";

                    strJson += "[";
                    strJson += "\"" + dt.Rows[j]["ID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["CustomerID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquNo"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["TaiHao"].ToString().Trim() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquNo"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquType"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["FangShaKind"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["UpdateTime"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["UseDate"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["MaintenanceCycle"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["MaintenanceDate"].ToString() + "\"";
                    strJson += "]";
                    strJson += "}";
                    if (j != pageSize + index - 1 && j != totalRecord - 1)
                    {
                        strJson += ",";
                    }
                }
            }
            else
            {
                strJson = "{\"page\":1,\"total\":0,\"records\":0,\"rows\":[";

            }
            strJson = strJson.Trim().TrimEnd(new char[] { ',' });
            strJson += "]}";
            return strJson;
        }

        /// <summary>
        /// 保存新增设备类型
        /// </summary>
        /// <param name="EquTypeName"></param>
        /// <param name="EquTypeRemark"></param>
        /// <param name="EquIndex"></param>
        /// <returns></returns>
        public string addEquTypeInfo(string EquTypeName, string EquTypeRemark, string EquIndex)
        {
            string json = EquInfoBLL.addEquTypeInfo(EquTypeName,EquTypeRemark,EquIndex);
            return json;
        }

        /// <summary>
        /// 删除设备类型信息
        /// </summary>
        /// <returns></returns>
        public string deleteEquTypeInfo()
        {
            string TypeID = RequstString("TypeID");

            string FeatureID = RequstString("FeatureID");

            string json = EquInfoBLL.deleteEquTypeInfo(TypeID,FeatureID);

            return json;
        }

        /// <summary>
        /// 删除设备信息
        /// </summary>
        /// <returns></returns>
        public string deleteEquInfo()
        {
            string EquID = RequstString("EquID");

            string json = EquInfoBLL.deleteEquInfo(EquID);

            return json;
        }

        public string deleteEquTypeInfoguidao()
        {
            string EquID = RequstString("ID");

            string json = EquInfoBLL.deleteEquTypeInfoguidao(EquID);

            return json;
        }
        /// <summary>
        /// 设置纺纱品种
        /// </summary>
        /// <param name="TaiHao"></param>
        /// <param name="FangShaKind"></param>
        /// <param name="CustomerID"></param>
        /// <returns></returns>
        public string savefangshakind(string TaiHao,string EquNo, string FangShaKind, string FangShaDate, string CustomerID)
        {
            string json = EquInfoBLL.savefangshakind(TaiHao,EquNo, FangShaKind,FangShaDate, CustomerID);
            return json;
        }

        /// <summary>
        /// 设置维护周期
        /// </summary>
        /// <param name="TaiHao"></param>
        /// <param name="MaintenanceCycle"></param>
        /// <param name="CustomerID"></param>
        /// <returns></returns>
        public string saveMaintenanceCycle(string TaiHao,string EquNo, string MaintenanceCycle, string CustomerID)
        {
            string json = EquInfoBLL.saveMaintenanceCycle(TaiHao,EquNo, MaintenanceCycle, CustomerID);
            return json;
        }

        /// <summary>
        /// 设备维护操作
        /// </summary>
        /// <param name="TaiHao"></param>
        /// <param name="CustomerID"></param>
        /// <returns></returns>
        public string maintenanceEquInfo(string TaiHao,string EquNo, string CustomerID)
        {
            string json = EquInfoBLL.maintenanceEquInfo(TaiHao,EquNo, CustomerID);
            return json;
        }

        public string addEquKaoHao(string EquNo,string  EquType,string Remark)
        {
            string json = EquInfoBLL.addEquKaoHao(EquNo,EquType,Remark);// EquInfoBLL.addEquTypeInfo(EquTypeName, EquTypeRemark, EquIndex);
            return json;
        }

        /// <summary>
        /// 保存编辑 设备类型 
        /// </summary>
        /// <param name="TypeID"></param>
        /// <param name="EquTypeName"></param>
        /// <param name="EquTypeRemark"></param>
        /// <param name="EquIndex"></param>
        /// <returns></returns>
        public string editequtype(string TypeID,string FeatureID,string EquTypeName,string EquTypeRemark,string EquIndex,string EquTypeFeatures,string FeaturesContent,string MaintenanceCycle,string ChangeEquNo)
        {
            string json = EquInfoBLL.editequtype(TypeID,FeatureID, EquTypeName, EquTypeRemark, EquIndex, EquTypeFeatures, FeaturesContent, MaintenanceCycle, ChangeEquNo);
            return json;
        }

        public string editequtypeguidao(string TypeID, string EquTypeName, string EquTypeRemark, string EquIndex)
        {
            string json = EquInfoBLL.editequtypeguidao(TypeID, EquTypeName, EquTypeRemark, EquIndex);
            return json;
        }

        /// <summary>
        /// 编辑设备类型初始化界面
        /// </summary>
        /// <returns></returns>
        public string initeditequtype()
        {
            string TypeID = RequstString("TypeID");

            string FeatureID = RequstString("FeatureID");

            string json = EquInfoBLL.initeditequtype(TypeID, FeatureID);

            return json;
        }

        /// <summary>
        /// 保存设备类型特性
        /// </summary>
        /// <param name="EquTypeFeatures"></param>
        /// <param name="FeaturesContent"></param>
        /// <param name="MaintenanceCycle"></param>
        /// <returns></returns>
        public string saveEquTypeFeature(string EquTypeFeatures,string FeaturesContent,string MaintenanceCycle)
        {
            string json = EquInfoBLL.saveEquTypeFeature(EquTypeFeatures, FeaturesContent, MaintenanceCycle);
            return json;
        }

        /// <summary>
        /// 得到设备类型特性列表
        /// </summary>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="EquTypeName"></param>
        /// <returns></returns>
        public string getEquTypeFeatureList(string sidx, string sord, string EquTypeName)
        {
            string strJson = "";
            DataTable dt = EquInfoBLL.getEquTypeFeatureList(sidx, sord, EquTypeName);

            if (dt != null)
            {
                string page = RequstString("page");
                //String page =Re .getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数 
                string rows = RequstString("rows");  // 取得每页显示行数，,注意这是jqgrid自身的参数 
                int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得，在此只是模拟) 
                int totalPage = totalRecord % Convert.ToInt16(rows) == 0 ? totalRecord
                / Convert.ToInt16(rows) : totalRecord / Convert.ToInt16(rows)
                + 1; // 计算总页数 
                int index = (Convert.ToInt16(page) - 1) * Convert.ToInt16(rows); // 开始记录数 
                int pageSize = Convert.ToInt16(rows);
                strJson = "{\"page\":" + page + ",\"total\": " + totalPage + "  ,\"records\":" + dt.Rows.Count.ToString() + ",\"rows\":[";
                for (int j = index; j < pageSize + index && j < totalRecord; j++)
                {
                    strJson += "{";
                    strJson += "\"id\":\"" + (j + 1).ToString() + "\",";
                    strJson += "\"cell\":";

                    strJson += "[";
                    strJson += "\"" + dt.Rows[j]["ID"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["EquTypeFeatures"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["FeaturesContent"].ToString() + "\",";
                    strJson += "\"" + dt.Rows[j]["MaintenanceCycle"].ToString() + "\"";
                    strJson += "]";
                    strJson += "}";
                    if (j != pageSize + index - 1 && j != totalRecord - 1)
                    {
                        strJson += ",";
                    }
                }
            }
            else
            {
                strJson = "{\"page\":1,\"total\":0,\"records\":0,\"rows\":[";

            }
            strJson = strJson.Trim().TrimEnd(new char[] { ',' });
            strJson += "]}";
            return strJson;
        }


        /// <summary>
        /// 编辑设备类型特性初始化界面
        /// </summary>
        /// <returns></returns>
        public string initEquTypeFeaterEditForm()
        {
            string FeatureID = RequstString("FeatureID");

            string json = EquInfoBLL.initEquTypeFeaterEditForm(FeatureID);

            return json;
        }

        //初始化设备报警编辑界面
        public string initeditequalarm()
        {
            string AlarmID = RequstString("AlarmID");

            string json = EquInfoBLL.initeditequalarm(AlarmID);

            return json;
        }

        /// <summary>
        /// 保存编辑设备类型特性
        /// </summary>
        /// <param name="FeatureID"></param>
        /// <param name="EquTypeFeatures"></param>
        /// <param name="FeaturesContent"></param>
        /// <param name="MaintenanceCycle"></param>
        /// <returns></returns>
        public string editEquTypeFeature(string FeatureID,string EquTypeFeatures,string FeaturesContent,string MaintenanceCycle)
        {
            string json = EquInfoBLL.editEquTypeFeature(FeatureID, EquTypeFeatures,FeaturesContent, MaintenanceCycle);
            return json;
        }

        /// <summary>
        /// 新增设备类型界面  如果点击关闭按钮  就删除未分配到设备类型的特性
        /// </summary>
        /// <returns></returns>
        public string deleteuntypefeature()
        {

            string json = EquInfoBLL.deleteuntypefeature();

            return json;
        }

        /// <summary>
        /// 保存新增设备类型   带有设备类型特性
        /// </summary>
        /// <param name="EquTypeName"></param>
        /// <param name="EquTypeRemark"></param>
        /// <param name="EquIndex"></param>
        /// <param name="EquTypeTexingID"></param>
        /// <returns></returns>
        public string saveEquTypeWithTexing(string EquTypeName, string EquTypeRemark, string EquIndex, List<string> EquTypeTexingID)
        {
            string json = EquInfoBLL.saveEquTypeWithTexing(EquTypeName, EquTypeRemark, EquIndex, EquTypeTexingID);
            return json;
        }

        /// <summary>
        /// 保存  编辑设备信息
        /// </summary>
        /// <param name="EquNo"></param>
        /// <param name="Remark"></param>
        /// <returns></returns>
        public string saveeditequ(string EquNo, string EquNewNo, string Remark)
        {
            string json = EquInfoBLL.saveeditequ(EquNo,EquNewNo, Remark);
            return json;
        }

        /// <summary>
        /// 保存  编辑设备故障信息
        /// </summary>
        /// <param name="AlarmID"></param>
        /// <param name="AlarmName"></param>
        /// <param name="AlarmHandle"></param>
        /// <param name="note"></param>
        /// <returns></returns>
        public string saveeditequalarm(string AlarmID,string AlarmName,string AlarmHandle,string note)
        {
            string json = EquInfoBLL.saveeditequalarm(AlarmID, AlarmName, AlarmHandle,note);
            return json;
        }


        public string initfangshabyid(string FangshaID)
        {
            return EquInfoBLL.initfangshabyid(FangshaID);
        }


        public string saveShengChanfangshakind(string FangShaKind,string CustomerID,string OutPutTarget,string FangShaDate)
        {
            return EquInfoBLL.saveShengChanfangshakind(FangShaKind, CustomerID, OutPutTarget, FangShaDate);
        }

        public string editShengChanfangshakind(string FangShaKind, string OutPutTarget, string FangShaDate, string ID)
        {
            return EquInfoBLL.editShengChanfangshakind(FangShaKind, OutPutTarget, FangShaDate, ID);
        }

        public string initShengChanSetInfo(string CustomerID)
        {
            return EquInfoBLL.initShengChanSetInfo(CustomerID);
        }

 



        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public static string RequstString(string sParam)
        {
            return (HttpContext.Current.Request[sParam] == null ? string.Empty
                  : HttpContext.Current.Request[sParam].ToString().Trim());
        }

        //定义一个类用来将前端传递过来的数据进行反序列化  
        public class MSG
        {
            public string Action { set; get; }
            public string EquTypeName { set; get; }
            public string EquTypeRemark { set; get; }
            public string EquIndex { set; get; }
            public List<string> EquTypeTexingID { set; get; }
        }  
    }
}